package com.example.menuvirtualclient;

import java.util.List;

import com.example.menuvirtualclient.adapter.EnquiryAdapter;
import com.example.menuvirtualclient.core.Enquiry;
import com.example.menuvirtualclient.presenter.EnquiryPresenter;
import com.example.menuvirtualclient.view.IEnquiryView;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

public class EnquiryActivity extends Activity implements IEnquiryView {

	private EnquiryPresenter _presenter;
	private ListView enquiryList;
	
		
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		if(savedInstanceState == null)
			Log.e("Error - onCreate() class EnquiryActivity", "savedInstanceState is null.");
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_enquiry);
		
		_presenter = new EnquiryPresenter(this);
		_presenter.LoadList();
	}
	
	@Override
	public void SetMessage(String title, String message) {
		ShowToast(message);
	}

	@Override
	public Context GetContext() {
		return getApplicationContext();
	}

	@Override
	public void ShowEnquiry(List<Enquiry> enquiries) {
		enquiryList = (ListView) findViewById(R.id.lstEnquiries);
		EnquiryAdapter enquiryAdapter = new EnquiryAdapter(this, R.layout.layout_enquiry_list, enquiries);
		enquiryList.setAdapter(enquiryAdapter);		
	}
	
	public void onSaveEnquiryClick(View button) {
		//AGREGAR LA PARTE DE RECUPERAR LOS ID DE CADA PREGUNTA Y EL VALOR
		_presenter.SaveEnquiryPerDay("1,8;2,2;3,10");
	}
	
	private void ShowToast(String message) {
		Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT);
		toast.show();
	}

	@Override
	public void CloseView() {
		finish();		
	}
	
}
